import {createAction, createAsyncAction} from 'typesafe-actions';
import {UserActionTypes, UserState} from './types';
// import {MeAPI} from '../../api';
// import {NetworkResponse} from '../../utils/network';

export const onDidLogin = createAction(UserActionTypes.DID_LOGIN)();

export const onWillLogout = createAction(UserActionTypes.WILL_LOGOUT)();

export const onUpdateUserInfo = createAction(UserActionTypes.UPDATE_USER_INFO)<
  Partial<UserState>
>();

export const {
  request: fetchUserInfoRequest,
  success: fetchUserInfoSuccess,
  failure: fetchUserInfoFailure,
} = createAsyncAction(
  UserActionTypes.FETCH_USER_REQUEST,
  UserActionTypes.FETCH_USER_SUCCESS,
  UserActionTypes.FETCH_USER_FAILURE,
)<
  undefined,
  {
    avatar: string;
    nickname: string;
    identity_status: number;
    introducer: string;
    user_tag: string[];
    profession_status: number;
    transaction: {
      [key: string]: number;
    };
    menu: {
      [menuItem: string]: any;
    };
    banner: Array<{
      url: string;
      action: string;
    }>;
  },
  any
>();
